import Vue from 'vue'
import Router from 'vue-router'
// import Main from '../views/Main.vue'


Vue.use(Router)
// Vue.prototype.axios = axios

const router = new Router({
  routes: [
  {
    path: '/',
    redirect: '/login'    //重定向
  },
  {
    path: '/login',
    name: 'login',
    // redirect: '/login',
    component: () => import('../views/login.vue'),
    
  },
  // {
  //   path:'/login1',
  //   component:()  =>
  //   import('../components/log/login1')
  // },
  
  {
    path: '/home',
    name: 'home',
    redirect: '/rwgl',
    //报错
    component: () => import('../views/home/index.vue'),
    children: [
      {
        path: '/rwsh',//任务审核
        name: 'rwsh',

        component: () => import('../components/rwsh.vue')
      },
      {
        path: '/ckrw',//查看任务
        name: 'ckrw',

        component: () => import('../components/ckrw.vue')
      },
      {
        path: '/rwgl',//任务管理
        name: 'rwgl',

        component: () => import('../components/rwgl.vue')
      },
      {
        path: '/zhgl',//账号管理
        name: 'zhgl',

        component: () => import('../components/zhgl.vue')
      },
      {
        path: '/sscl',//申诉处理
        name: 'sscl',

        component: () => import('../components/sscl.vue')
      },
      {
        path: '/txcz',//提现充值
        name: 'txcz',

        component: () => import('../components/txcz.vue')
      },

    ]
  },
  {
    path: '/home',
    // name: 'home',
    redirect: '/rwdt',
    //报错
    component: () => import('../views/home/EnterpriseIndex.vue'),
    children: [
      {
        path: '/qyrwdt',//企业端任务大厅
        name: 'qyrwdt',

        component: () => import('../components/Enterprise/qyrwdt.vue')
      },
      {
        path: '/qyrwgl',//企业端任务管理
        name: 'qyrwgl',

        component: () => import('../components/Enterprise/qyrwgl.vue'),
      },
      {
        path: '/Beforeqyzx',//企业端企业中心认证前的企业中心
        name: 'Beforeqyzx',

        component: () => import('../components/Enterprise/Beforeqyzx.vue')
      },
      {
        path: '/qyzx',//企业端企业中心
        name: 'qyzx',

        component: () => import('../components/Enterprise/qyzx.vue')
      },
      {
        path: '/fbrw',//企业端发布任务
        name: 'fbrw',

        component: () => import('../components/Enterprise/fbrw.vue')
      },
      {
        path: '/qyrz',//企业端认证
        name: 'qyrz',

        component: () => import('../components/Enterprise/qyrz.vue')
      },
      {
        path: '/rwxq',//企业端任务详情
        name: 'rwxq',

        component: () => import('../components/Enterprise/rwxq.vue')
      },
    ],
  },
  {
    path: '/home',
    // name: 'home',
    redirect: '/Userrwdt',
    //报错
    component: () => import('../views/home/UserIndex.vue'),
    children: [
      {
        path: '/Userrwdt',//用户端任务大厅
        name: 'Userrwdt',

        component: () => import('../components/Users/Userrwdt.vue')
      },
      {
        path: '/Userrwgl',//用户端任务管理
        name: 'Userrwgl',

        component: () => import('../components/Users/Userrwgl.vue')
      },
      {
        path: '/Usergrzx',//用户端个人中心
        name: 'Usergrzx',

        component: () => import('../components/Users/Usergrzx.vue')
      },
      {
        path: '/Usertjrw',//用户端提交任务
        name: 'Usertjrw',

        component: () => import('../components/Users/Usertjrw.vue')
      },
      {
        path: '/Userrwxq',//用户端任务详情
        name: 'Userrwxq',

        component: () => import('../components/Users/Userrwxq.vue')
      },
    ]
  },
  {
    path: '/register',//注册界面
    name: 'register',

    component: () => import('../components/register.vue')
  },
  {
    path: '/forget',//忘记密码
    name: 'forget',

    component: () => import('../components/forget.vue')
  },

]
})


/* 为了防止直接输入地址进入主界面 */
/* router.beforeEach(function(to,from,next){
  if(!sessionStorage.getItem('username')){
    if(to.path !== '/login'){
      next('/login')
    }
  };
  next();
})
 */
router.beforeEach((to,from,next) => {
  if(to.path === '/login') return next();
  if(to.path === '/register') return next();
  if(to.path === '/forget') return next();
const tokenStr =  window.sessionStorage.getItem('token')
if(!tokenStr)return next('/login')

next()
// return config; 

})
 
export default router
